package com.guo.core.framework.suanfa;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.junit.Test;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @projectName: 接口梳理
 * @package: com.guo.core.framework.suanfa
 * @className: lingdanTest
 * @author: zhangcan30
 * @description: TODO
 * @date: 2023/3/1 16:39
 * @version: 1.0
 */
public class lingdanTest {
    @Test
    public void 张灿插入数据() throws SQLException {

        String fileName1 = "C:/Users/zhangcan30/Desktop/零担下发EXCEL/数据库数据.xlsx";
        ExcelReader reader1 = ExcelUtil.getReader(fileName1, 0);
        List<Map<String, Object>> readAll1 = reader1.readAll();

        String fileName2 = "C:/Users/zhangcan30/Desktop/零担下发EXCEL/拷贝所有数据.xlsx";
        ExcelReader reader2 = ExcelUtil.getReader(fileName2, 0);
        List<Map<String, Object>> readAll2 = reader2.readAll();

        Map<Map<String, Object>, Integer> map = new HashMap<>();

        for (Map<String, Object> data : readAll1) {
            map.put(data,1);
        }

        for (Map<String, Object> data : readAll2) {
            Integer value = map.get(data);
            if (value!=null){
                map.put(data,++value);
                continue;
            }
            map.put(data,1);
        }

        List<Map<String, Object>> different = new ArrayList<>();
        for (Map.Entry<Map<String, Object>, Integer> entry : map.entrySet()) {
            //获取不同元素集合
            if (entry.getValue() == 1) {
                different.add(entry.getKey());
            }
        }
        System.out.println(different.size());
        ZipSecureFile.setMinInflateRatio(-1.0d);
        ExcelWriter writer = new ExcelWriter("C:/Users/zhangcan30/Desktop/零担下发EXCEL/差异数据aaa.xlsx");
        writer.write(different, true);
        writer.close();
    }
}
